<?php 
declare(strict_types=1);
namespace App\Service;

use App\Dao\AreaDao;

 class AreaService
 {

     /**
      * 获取市级地区列表
      * @return array
      */
     public function list()
     {

         $data = make(AreaDao::class)->getList();
         $list = [];

         if(!empty($data)){
             foreach ($data as $k => $v) {
                 if(!key_exists($v['parent_id'], $list)){
                     $list[$v['parent_id']]['province_id'] = $v['parent_id'];
                     $list[$v['parent_id']]['province_name'] = $v['province'];
                 }
                 $list[$v['parent_id']]['city_list'][] = [
                     'city_id' => $v['id'],
                     'city_name' => $v['nick_name']
                 ];
             }
         }
         unset($data);

         return $list;

     }

 }